package de.rs.espresso;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.Scanner;

public class Verify {

	private static String abcPath = "C:\\Users\\Jan\\Downloads\\blif\\abc.exe";

	private static String verifyPath = "C:\\Users\\Jan\\Downloads\\blif\\";

	public static void main(String[] args) {

		try {
			File path = new File(verifyPath);

			for (String s : path.list()) {
				File f = new File(path.getAbsolutePath() + "/" + s);
				if (f.isFile() && s.endsWith(".blif")
						&& !s.endsWith("_minimized.blif")) {
					
					

					String name = s.substring(0, s.lastIndexOf('.'));
					
					//System.out.println("Process "+name+"...");
					
					ProcessBuilder builder = new ProcessBuilder(abcPath, "-c",
							"\"cec " + name + ".blif " + name
									+ "_minimized.blif\"");
					builder.directory(path);
					Process p;

					p = builder.start();

					p.waitFor();

					Scanner scanner = new Scanner(p.getInputStream());
					scanner.useDelimiter("\\Z");

					System.out.println("Result for "+ name + ".blif and " + name
									+ "_minimized.blif: "+scanner.next());

					scanner.close();
					
					p.destroy();

				}
			}

		} catch (IOException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		System.exit(0);
	}

}
